PACKAGE = xwm
SYSCONF = $(DESTDIR)@SYSCONF@
MANDIR = $(DESTDIR)@MANDIR@
DATADIR = $(DESTDIR)@DATADIR@
ICONDIR = $(DESTDIR)@ICONDIR@
VERSION ?= @VERSION@
USE_NLS = @USE_NLS@
SUBDIRS = m4 po

all:
	$(MAKE) -C src all
	$(MAKE) -C po all

install: all
	$(MAKE) -C src install
	$(MAKE) -C po install
	$(MAKE) -C contrib install
	install -d -m 0755 $(SYSCONF)/xdg/xwm
	install -m 644 data/example.xwmrc $(SYSCONF)/xdg/xwm/rc.xml
	install -m 755 data/autostart $(SYSCONF)/xdg/xwm/autostart
	install -d -m 0755 $(DATADIR)/xsessions
	install -m 644 data/xwm.desktop $(DATADIR)/xsessions/xwm.desktop
	install -d -m 0755 $(MANDIR)/man1
	install -m 644 data/xwm.1 $(MANDIR)/man1/xwm.1

install-strip: all install-conf
	$(MAKE) -C src install-strip
	$(MAKE) -C po install-strip
	$(MAKE) -C contrib install
	install -d -m 0755 $(SYSCONF)/xdg/xwm
	install -m 644 data/example.xwmrc $(SYSCONF)/xdg/xwm/rc.xml
	install -m 755 data/autostart $(SYSCONF)/xdg/xwm/autostart
	install -d -m 0755 $(DATADIR)/xsessions
	install -m 644 data/xwm.desktop $(DATADIR)/xsessions/xwm.desktop
	install -d -m 0755 $(MANDIR)/man1
	install -m 644 data/xwm.1 $(MANDIR)/man1/xwm.1
	install -d -m 0755 $(ICONDIR)

uninstall:
	$(MAKE) -C src uninstall
	$(MAKE) -C po uninstall
	$(MAKE) -C contrib uninstall
	rm -f $(SYSCONF)/system.xwmrc

tarball:
	rm -f ../xwm-$(VERSION).tar.xz ;
	rm -fr ../xwm-$(VERSION) ;
	cp -r ../xwm ../xwm-$(VERSION) ;
	(cd ../xwm-$(VERSION) && $(MAKE) distclean) ;
	(cd .. && tar -cf xwm-$(VERSION).tar xwm-$(VERSION));
	rm -fr ../xwm-$(VERSION) ;
	(cd .. && xz xwm-$(VERSION).tar)

clean:
	(cd src && $(MAKE) clean)
	(cd po && $(MAKE) clean)
	rm -rf doc

distclean: clean
	rm -f *[~#] config.cache config.log config.status config.h
	rm -f Makefile src/Makefile data/xwm.1
	rm -fr autom4te.cache
	rm -f Makefile.bak src/Makefile.bak

check-gettext:
	@if test x$(USE_NLS) != "xyes" ; then \
		echo "Missing gettext. Rerun configure and check for" \
			"'checking whether to use NLS... yes'!" ; exit 1 ; fi

update-po: check-gettext
	@find src/ -name "*.c" -print | sort > po/POTFILES.in.2 ; \
	if diff po/POTFILES.in po/POTFILES.in.2 >/dev/null 2>&1 ; then \
	   rm -f po/POTFILES.in.2 ; \
	else \
	   mv po/POTFILES.in.2 po/POTFILES.in ; \
	fi
	cd po && $(MAKE) $(AM_MAKEFLAGS) update-po

update-gmo: check-gettext
	cd po && $(MAKE) $(AM_MAKEFLAGS) update-gmo

force-update-gmo: check-gettext
	touch po/*.po
	cd po && $(MAKE) $(AM_MAKEFLAGS) update-gmo

.PHONY: check-gettext update-po update-gmo force-update-gmo
